package cn.tedu.analyse.controller;

import cn.tedu.analyse.pojo.param.RepliesParam;
import cn.tedu.analyse.pojo.vo.RepliesVO;
import cn.tedu.analyse.response.JsonResult;
import cn.tedu.analyse.service.RepliesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/replies")
@Api(tags = "回复")
public class RepliesController {
    @Autowired
    private RepliesService repliesService;



    @ApiOperation("创建回复")
    @PostMapping("create")
    public JsonResult createReply( @RequestBody RepliesParam repliesParam){
        log.debug("创建回复，参数：{}",repliesParam);

        repliesService.createReply(repliesParam);
        return JsonResult.ok();
    }
    @ApiOperation("删除回复")
    @DeleteMapping("delete/{repliesId}")
    public JsonResult deleteReply(@PathVariable Long repliesId){
        log.debug("删除回复，参数：{}",repliesId);
        repliesService.deleteReply(repliesId);
        return JsonResult.ok();
    }
    @ApiOperation("查询回复")
    @GetMapping("list/{analyseCommentsId}")
    public JsonResult listReplies(@PathVariable Long analyseCommentsId){
        log.debug("查询回复，参数：{}",analyseCommentsId);
        List<RepliesVO> list = repliesService.listReplies(analyseCommentsId);
        return JsonResult.ok(list);
    }

    @ApiOperation("查询回复id")
    @GetMapping("{repliesId}")
    public JsonResult getReplies(@PathVariable Long repliesId){
        log.debug("查询回复id，参数：{}",repliesId);
        RepliesVO repliesVO = repliesService.getReplies(repliesId);
        return JsonResult.ok(repliesVO);
    }
    @ApiOperation("查询多级回复")
    @GetMapping("list/getParent/{parentId}")
    public JsonResult listRepliesByParentId(@PathVariable Long parentId){
        log.debug("查询多级回复，参数：{}",parentId);
        List<RepliesVO> list = repliesService.listRepliesByParentId(parentId);
        return JsonResult.ok(list);
    }
}
